import { CommonWidgetNames, FieldPropsDefine } from "../types";
import { computed, defineComponent } from "vue";
import { getWidget } from "../theme";
export default defineComponent({
  name: "StringField",
  props: FieldPropsDefine,
  setup(props) {
    const handleChange = (v: string) => {
      props.onChange(v);
    };
    const TextWidgetRef = computed(() => {
      const widgetRef = getWidget(CommonWidgetNames.TextWidget, props);
      return widgetRef.value;
    });

    const widgetOptionsRef = computed(() => {
      const { widget, properties, items, ...rest } = props.uiSchema;
      return rest;
    });

    return () => {
      const { rootSchema, errorSchema, ...rest } = props;
      const TextWidget = TextWidgetRef.value;
      return (
        <TextWidget
          errors={errorSchema.__errors}
          {...rest}
          options={widgetOptionsRef.value}
          onChange={handleChange}
        ></TextWidget>
      );
      /* return (
        <input value={props.value as any} type="text" onInput={handleChange}></input>
      ); */
    };
  },
});
